<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>选择产品</title>
<%@ include file="../../../jsp/commons/headfiles-jquery.jsp"%>
</head>
<body>

	<form class="form-horizontal">
		<div class="control-group">
			<label class="control-label" for="pcode">代码</label>
			<div class="controls">
				<input id="pcode" type="text" data-provide="typeahead" />
			</div>
		</div>

        <%
        	org.jackysoft.entity.ProductType[] ptypes = org.jackysoft.entity.ProductType.values();
                		pageContext.setAttribute("ptypes", ptypes);
        %>

		<div class="control-group">
			<label class="control-label" for="itemType">类型</label>
			<div class="controls">
				<select id="itemType">
					<c:forEach items="${ptypes}" var="pt">
						<option value="${pt}">${pt}</option>
					</c:forEach>
				</select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label" for="pname">名称</label>
			<div class="controls">
				<input type="text" id="pname" readOnly />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">动工</label>
			<div class="controls">
				<input id="paction" type="text"  onblur="judgeNumber(this)" value="0" />
			</div>
		</div>

		<div class="control-group">
			<label class="control-label" for="ppassed">验收</label>
			<div class="controls">
				<input id="ppassed"  type="text" onblur="judgeNumber(this)" value="0" />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label" for="pwaster">废品</label>
			<div class="controls">
				<input id="pwaster"  type="text" onblur="judgeNumber(this)" value="0" />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label" for="ptest">试销</label>
			<div class="controls">
				<input id="ptest"  type="text" onblur="judgeNumber(this)" value="0" />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label" for="premark">备注</label>
			<div class="controls">
				<textarea id="premark"></textarea>
			</div>
		</div>
		<div class="control-group">
			<div class="controls">
				<button class="btn" onclick="closeMe();" type="button">关闭</button>
				<button class="btn btn-success" onclick="addLine();" type="button">添加</button>
			</div>
		</div>
	</form>



	
	
	<script type="text/javascript">
        var par = window.dialogArguments;       
		$(function() {
			setAutoComplete("#pcode");
		});
		
		
		function setAutoComplete(objId) {
            var obj = $(objId);
			obj.autocomplete({
				minLength : 3,
				source : function(request, response) {
					var term = request.term;
					$.getJSON(
							"../../product/product!searchall", 
							{"term" : term}, 
							function(data) {
								response(data);
							}							
					);
				},
				focus : function(event, ui) {
					obj.val(ui.item.code);
					return false;
				},
				select : function(event, ui) {
					obj.val(ui.item.code);
				    $("#pname").val(ui.item.name);
					return false;
				}

			}).data("autocomplete")._renderItem = function(ul, item) {
				return $("<li></li>").data("item.autocomplete", item).append(
						"<a>" + item.code + "|" + item.name + "</a>").appendTo(ul);
			};
		}
		
		function closeMe(){
			window.opener=null;
			window.close();
		}
		
		function addLine(){		
			par.addDataLine(
					$("#pcode").val(),
					$("#pname").val(),
					$("#paction").val(),
					$("#ppassed").val(),
					$("#pwaster").val(),
					$("#ptest").val(),
					$("#premark").text(),
					$("#itemType").val()); 
			$("form").get(0).reset();
		}
	</script>
</body>
</html>